package cn.com.haopy.dataes.db.service.service.impl;

import cn.com.haopy.dataes.db.entity.service.HStore;
import cn.com.haopy.dataes.db.mapper.service.HStoreMapper;
import cn.com.haopy.dataes.db.service.service.HStoreService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class HStoreServiceImpl extends ServiceImpl<HStoreMapper, HStore> implements HStoreService {

    @Override
    public Page<HStore> querySelective(Integer pageNo, Integer size, String sort, String order) {

        QueryWrapper<HStore> queryWrapper = new QueryWrapper<>();

        if (StringUtils.hasText(sort) && StringUtils.hasText(order)) {
            queryWrapper.orderBy(true, "asc".equals(order), sort);
        }

        Page<HStore> page = new Page<>(pageNo, size);

        return super.page(page, queryWrapper);
    }

    @Override
    public List<HStore> queryLimit(Integer limit) {
        LambdaQueryWrapper<HStore> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.last("limit " + limit);
        return super.list(queryWrapper);
    }
}
